package website.seamonster.ethegg.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import website.seamonster.ethegg.dataobject.Transaction;

import java.math.BigDecimal;
import java.util.List;

/**
 * Created by 罗海量
 * 2018-07-17 19:04
 */
public interface TransactionRepository extends JpaRepository<Transaction, String> {
    Transaction findFirstByTxStatusOrderByTxReqIdAsc(Integer txStatus);

    List<Transaction> findAllByTxReqId(Long txReqId);

    @Query("select sum(t.sellIncome) from Transaction t where t.sellId=?1 and t.txStatus=?2")
    BigDecimal sumSellIncome(String sellerUserId, Integer txStatusSuccess);

    @Query("select sum(t.prIncome) from Transaction t where t.prUserId=?1 and t.txStatus=?2")
    BigDecimal sumPrIncome(String prUserId, Integer txStatusSuccess);

}
